//
//  HomeViewController.m
//  Medgretraining
//
//  Created by 辰领科技 on 16/5/17.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "HomeViewController.h"
#import "HouseCleanViewController.h"
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#import <CoreLocation/CLLocationManagerDelegate.h>
#import "DbDao.h"
#import "CityArea.h"
#import "STActionSheet.h"
#import "HomeDetailServiceCollectionViewCell.h"
#import "MoreServiceViewController.h"
#import "HomeServiceCollectionViewCell.h"
#import "MouthSerciveViewController.h"
#import "DetailWebViewController.h"
#import "HotRecommendTableViewCell.h"

static NSString * hotcellIndentifer = @"HotRecommendTableViewCell";
static NSString * cellIndentifer = @"HomeServiceCollectionViewCell";
static NSString * detailCellIndentifer = @"HomeDetailServiceCollectionViewCell";
@interface HomeViewController ()<BestScrollViewDelegate,BestScrollViewDatasource,CLLocationManagerDelegate,UICollectionViewDataSource,UICollectionViewDelegate,UITableViewDataSource,UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UIScrollView *scroView;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UICollectionView *serviceCollectionView;

@property (weak, nonatomic) IBOutlet UICollectionView *DetailServiceCollectionView;
@property (nonatomic,strong)  BestScrollView *headerScroll;//滚动栏
@property (nonatomic,strong)  BestScrollView *footerScroll;//底部滚动栏
@property (nonatomic,strong)  NSMutableArray  *imageArray;
@property (nonatomic,strong)  NSMutableArray  *footerImageArray;
@property(nonatomic,strong)CLLocationManager * locationManger;
@property (weak, nonatomic) IBOutlet UIButton *locationButton;
@property(nonatomic,assign)NSInteger indexId;
@property(nonatomic,strong)NSMutableArray * indexOneArray;
@property(nonatomic,strong)NSMutableArray * indexTwoArray;

@property(nonatomic,strong)NSMutableArray * sectionArray;
@property(nonatomic,strong)NSString * phoneNum;

@property(nonatomic,strong)NSMutableArray * hotRecommendArray;
@end

@implementation HomeViewController

- (void)viewWillAppear:(BOOL)animated{
    [self getAdvertiseBanner];
    [self getFooterAdvertiseBanner];
    [self getHotRecommend];
    [self getGoodsListTwo];
    [self getPhoneNumber];
    [self startLocation];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.imageArray = [NSMutableArray array];
    self.hotRecommendArray = [NSMutableArray array];
    self.footerImageArray = [NSMutableArray array];
     _indexId = 1;
     _indexOneArray = [NSMutableArray array];
    NSArray * names = @[@"家庭保洁",@"家电清洁",@"家居保养",@"开荒保洁",@"保姆月嫂",@"企业服务",@"叮咚速运",@"更多服务"];
    for (int i = 0; i<names.count; i++) {
        NSMutableDictionary * dic = [NSMutableDictionary dictionary];
        [dic setObject:names[i] forKey:@"mgooName"];
        [dic setObject:[NSString stringWithFormat:@"%d",20160519+i] forKey:@"mgooId"];
        [dic setObject:[NSString stringWithFormat:@"home%d",i+1] forKey:@"mgooImage"];
        [_indexOneArray addObject:dic];
    }
   
    _indexTwoArray = [NSMutableArray array];
    _sectionArray = [NSMutableArray array];
    [self configurationNavigationAndTabbar];
    [self initViewLayout];
    
    // Do any additional setup after loading the view.
}


- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroView];

    _scroView.frame = CGRectMake(0, 64* VerticalRatio(), 320* VerticalRatio(), (568-64)* VerticalRatio()-49);
    _scroView.contentSize = flexibleSize(CGSizeMake(0, 1100), NO);
    
    //广告栏
    _headerScroll=[[BestScrollView alloc]  initWithFrame:flexibleFrame(CGRectMake(0, 0, 320, 140), NO)];
    [self.scroView addSubview:_headerScroll];
    
    //底部广告栏
    _footerScroll=[[BestScrollView alloc]  initWithFrame:flexibleFrame(CGRectMake(0, 516, 320, 100), YES)];
    [self.scroView addSubview:_footerScroll];
    

    
    UICollectionViewFlowLayout *FlowLayout =[[UICollectionViewFlowLayout alloc]init];
    FlowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    FlowLayout.minimumInteritemSpacing = 0*VerticalRatio();
    FlowLayout.minimumLineSpacing = 0*VerticalRatio();
    self.serviceCollectionView.collectionViewLayout = FlowLayout;
    self.serviceCollectionView.userInteractionEnabled=YES;
    _serviceCollectionView.delegate = self;
    _serviceCollectionView.dataSource = self;
    _serviceCollectionView.pagingEnabled = YES;
    [self.serviceCollectionView registerNib:[UINib nibWithNibName:cellIndentifer bundle:nil] forCellWithReuseIdentifier:cellIndentifer];
    
    UICollectionViewFlowLayout *hFlowLayout =[[UICollectionViewFlowLayout alloc]init];
    hFlowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    hFlowLayout.minimumInteritemSpacing =  0*VerticalRatio();
    hFlowLayout.minimumLineSpacing = 0*VerticalRatio();
    self.DetailServiceCollectionView.collectionViewLayout = hFlowLayout;
    self.DetailServiceCollectionView.userInteractionEnabled=YES;
    [self.DetailServiceCollectionView registerNib:[UINib nibWithNibName:detailCellIndentifer bundle:nil] forCellWithReuseIdentifier:detailCellIndentifer];
    
    //注册
    [self.tableView registerNib:[UINib nibWithNibName:hotcellIndentifer bundle:nil] forCellReuseIdentifier:hotcellIndentifer];
    _tableView.dataSource = self;
    _tableView.delegate = self;

}

#pragma mark === 获取服务

- (void)getGoodsListTwo{
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:@"5" forKey:@"indexId"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:HK_queryCountOne withHttpType:@"POST" withTag:HK_HK_queryCountTwo];
}

#pragma mark ==== 客服电话
- (void)getPhoneNumber {
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    self.shareApi.delegate = self;
    [self.shareApi  requestOperationWithDic:dic withPath:HK_contactInformation withHttpType:@"POST" withTag:HK_HK_contactInformation];
}

#pragma mark ==== 切换区
- (IBAction)sectionHandel:(id)sender {
    
    NSDictionary *att = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:15*VerticalTexeRatio()],
                          NSForegroundColorAttributeName:[UIColor blackColor]};
    STActionSheet *actionSheet = [[STActionSheet alloc] initWithTitle:nil cancelTitle:nil otherButtonTitles: _sectionArray attribute:att];
    actionSheet.hideWhenTouchOutside = YES;
    [actionSheet setActionHandler:^(STActionItem *item, NSInteger index){
        [_locationButton setTitle:_sectionArray[index] forState:UIControlStateNormal];
    }];
    [actionSheet show:YES];

}

#pragma mark   === 拨号
- (IBAction)callHandel:(id)sender {
    [Common callPhone:_phoneNum view:self.view];
}

#pragma mark -- coreLocation

- (void)startLocation{
    
    // 判断定位操作是否被允许
    
    if([CLLocationManager locationServicesEnabled]) {
        
        _locationManger = [[CLLocationManager alloc] init];
        _locationManger.delegate = self;
        _locationManger.desiredAccuracy = kCLLocationAccuracyBest;
        _locationManger.distanceFilter = 5.0f;
        // 总是授权
        [_locationManger requestAlwaysAuthorization];
        if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8) {
            [_locationManger requestWhenInUseAuthorization];//使用程序其间允许访问位置数据（iOS8定位需要）
            [_locationManger requestAlwaysAuthorization];
        }
        [_locationManger startUpdatingLocation];
        
        
    }else {
        
        //提示用户无法进行定位操作
        
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"定位不成功 ,请确认开启定位" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        
        [alertView show];
        
    }
    // 开始定位
    [_locationManger startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
    CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
    [geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
        for (CLPlacemark * placemark in placemarks) {
            
            NSDictionary *test = [placemark addressDictionary];
            //  Country(国家)  State(城市)  SubLocality(区)
            NSString * cityName = test[@"SubLocality"];
            [_locationButton setTitle:cityName forState:UIControlStateNormal];
            
            
            DbDao *dao = [DbDao sharedInstance];
            NSArray *cityArr = [dao getCityArea:[NSString stringWithFormat:@"select * from sys_area where a_name = '%@'",test[@"State"]]];
            CityArea *area = cityArr[0];
            NSArray *areaArr = [dao getCityArea:[NSString stringWithFormat:@"select * from sys_area where a_parent_id = %d",area.a_id]];
            [_sectionArray removeAllObjects];
            for (CityArea *area  in areaArr) {
                [_sectionArray addObject:area.a_name];
            }
            
            
            CityArea *sectionArea = [dao getCityArea:[NSString stringWithFormat:@"select * from sys_area where a_name = '%@'",cityName]][0];
            NSString * sectionId = [NSString stringWithFormat:@"%d",sectionArea.a_id];
            [[NSUserDefaults standardUserDefaults]setObject:sectionId forKey:@"sectionId"];
       }
    }];
    [_locationManger stopUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
    NSLog(@"%@",error);
}



#pragma mark  获取首页广告BANNER--=========================================
-(void)getAdvertiseBanner{
    
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:@"1" forKey:@"Id"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:HK_kADBannerTag withHttpType:@"POST" withTag:HK_HK_kADBannerTag];
}

- (void)getFooterAdvertiseBanner{
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:@"6" forKey:@"Id"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:HK_kADBannerTag withHttpType:@"POST" withTag:HK_HK_footerADBannerTag];
}

- (void)getHotRecommend{
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:@"5" forKey:@"Id"];
    self.shareApi.delegate=self;
    [self.shareApi  requestOperationWithDic:dic withPath:HK_kADBannerTag withHttpType:@"POST" withTag:HK_HK_hotRecommendTag];
}



#pragma mark -- UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _hotRecommendArray.count;
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   
    return 150*VerticalRatio() ;
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    HotRecommendTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:hotcellIndentifer];
    if (cell == nil) {
        cell= [[HotRecommendTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:hotcellIndentifer];
    }
    NSDictionary * dic =_hotRecommendArray[indexPath.row];
    NSString * image = [NSString stringWithFormat:@"%@",dic[@"titleimg"]];
    if (image && image.length>0) {
        [cell.backImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,image]]];
    }

    return cell;
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary * dic =_hotRecommendArray[indexPath.row];
    NSString * linkAddress = [NSString stringWithFormat:@"%@",dic[@"linkaddress"]];
    if ([linkAddress isEqualToString:@""]||[linkAddress isEqualToString:@"<null>"]) {
        UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
        HouseCleanViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"HouseClean"];
        page.goodsId = [NSString stringWithFormat:@"%@",dic[@"cityid"]];
        [[Common getNavigation]pushViewController:page];
    }else{
        UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
        DetailWebViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"DetailWeb"];
        page.webId = linkAddress;
        [[Common getNavigation]pushViewController:page];

    }
}

#pragma mark -- UICollectionViewDataSource
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if ([collectionView isEqual:self.serviceCollectionView]) {
        return _indexOneArray.count;
    }else if([collectionView isEqual:self.DetailServiceCollectionView]){
        return _indexTwoArray.count;
    }
    return 0;
}
//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if ([collectionView isEqual:self.serviceCollectionView]) {
        return CGSizeMake(80*VerticalRatio(), 95*VerticalRatio());
    }else if([collectionView isEqual:self.DetailServiceCollectionView]){
        return CGSizeMake(158*VerticalRatio(), 60*VerticalRatio());

    }
     return CGSizeMake(0*VerticalRatio(), 0*VerticalRatio());;
}
//定义每个UICollectionView 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    if ([collectionView isEqual:self.serviceCollectionView]) {
        return UIEdgeInsetsMake(0,0*VerticalRatio(), 0*VerticalRatio(), 0*VerticalRatio());
    }else if([collectionView isEqual:self.DetailServiceCollectionView]){
        return UIEdgeInsetsMake(1,1, 0, 0);
    }
        
        return UIEdgeInsetsMake(0,0, 0*VerticalRatio(), 0*VerticalRatio());
    
    
    
}
//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if ([collectionView isEqual:self.serviceCollectionView]) {
        HomeServiceCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIndentifer forIndexPath:indexPath];
        NSDictionary * dic = _indexOneArray[indexPath.row];
        NSString * image = [NSString stringWithFormat:@"%@",dic[@"mgooImage"]];
        cell.serviceImage.image = [UIImage imageNamed:image];
        
        cell.serviceName.text = [NSString stringWithFormat:@"%@",dic[@"mgooName"]];
        return cell;
        
    }else if([collectionView isEqual:self.DetailServiceCollectionView]){
        HomeDetailServiceCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:detailCellIndentifer forIndexPath:indexPath];
        NSDictionary * dic = _indexTwoArray[indexPath.row];
        NSString * image = [NSString stringWithFormat:@"%@",dic[@"mgooImage"]];
        if (image && image.length>0) {
            [cell.serviceImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,image]]];
        }
        cell.serviceName.text = [NSString stringWithFormat:@"%@",dic[@"mgooName"]];
        UIColor * color1 = [UIColor colorWithRed:0.282 green:0.753 blue:0.690 alpha:1.000];
        UIColor * color2 = [UIColor colorWithRed:1.000 green:0.455 blue:0.000 alpha:1.000];
         UIColor * color3 = [UIColor colorWithRed:1.000 green:0.376 blue:0.314 alpha:1.000];
         UIColor * color4 = [UIColor colorWithRed:0.451 green:0.643 blue:0.961 alpha:1.000];
        UIColor * color5 = [UIColor colorWithRed:0.427 green:0.800 blue:0.282 alpha:1.000];
        UIColor * color6 = [UIColor colorWithRed:0.776 green:0.451 blue:0.961 alpha:1.000];
        NSArray * colors = @[color1,color2,color3,color4,color5,color6];
         cell.serviceName.textColor = colors[indexPath.row];
        cell.serviceDetail.text = [NSString stringWithFormat:@"%@",dic[@"mgooSubTitle"]];
       
        return cell;
    }
    return nil;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
   
    if ([collectionView isEqual:self.serviceCollectionView]) {
        if (indexPath.row == 6) {
            UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"敬请期待！" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alertView show];
        }else if (indexPath.row == 7||indexPath.row == 1|| indexPath.row==2||indexPath.row == 4) {
            UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
            MoreServiceViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"MoreService"];
            if (indexPath.row == 1) {
                page.typeStr =@"3";
            }else if( indexPath.row==2){
                page.typeStr = @"2";
            }else if( indexPath.row==4){
                page.typeStr = @"4";
            }
            [[Common getNavigation]pushViewController:page];
        }else {
            UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
            HouseCleanViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"HouseClean"];
            page.goodsId = [NSString stringWithFormat:@"%@",_indexOneArray[indexPath.row][@"mgooId"]];
            [[Common getNavigation]pushViewController:page];
        }

    }else if ([collectionView isEqual:self.DetailServiceCollectionView]) {
        NSString * serviceName = _indexTwoArray[indexPath.row][@"mgooName"];
        if ([serviceName isEqualToString:@"包月服务"]) {
            UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
            MouthSerciveViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"MouthSercive"];
            page.goodsId = [NSString stringWithFormat:@"%@",_indexTwoArray[indexPath.row][@"mgooId"]];
            page.goodsName = [NSString stringWithFormat:@"%@",_indexTwoArray[indexPath.row][@"mgooName"]];
            [[Common getNavigation]pushViewController:page];
        }else{
            UIStoryboard *secondStroyBoard=[UIStoryboard storyboardWithName:@"HomeStoryboard" bundle:nil];
            HouseCleanViewController *page = [secondStroyBoard instantiateViewControllerWithIdentifier:@"HouseClean"];
            page.goodsId = [NSString stringWithFormat:@"%@",_indexTwoArray[indexPath.row][@"mgooId"]];
            [[Common getNavigation]pushViewController:page];
        }
        
    }
}


#pragma  mark BestView Delegate Data=source=====================


- (NSInteger)numberOfPagesatView:(BestScrollView *)bsView
{
    if (bsView == _headerScroll) {
        return  self.imageArray.count;
    }else if (bsView == _footerScroll){
        return self.footerImageArray.count;
    }
    return 0;
}




- (UIView *)pageAtIndex:(NSInteger)index atView:(BestScrollView*)bsView

{
    if (bsView == _headerScroll) {
        if (self.imageArray.count>0) {
            UIImageView  *imageView=[[UIImageView alloc]  initWithFrame: flexibleFrame(CGRectMake(0, 0, 320, 140), NO)];
            [imageView  sd_setImageWithURL:[NSURL URLWithString: [NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,_imageArray[index][@"titleimg"]]] placeholderImage:[UIImage imageNamed:@"integral2"]];
            return imageView;
        }
    }else if (bsView == _footerScroll){
        if (self.footerImageArray.count>0) {
            UIImageView  *imageView=[[UIImageView alloc]  initWithFrame: flexibleFrame(CGRectMake(0, 0, 320, 100), NO)];
            [imageView  sd_setImageWithURL:[NSURL URLWithString: [NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,_footerImageArray[index][@"titleimg"]]] placeholderImage:[UIImage imageNamed:@"integral2"]];
            return imageView;
        }
    }
    
    return nil;
}


- (void)didClickPage:(BestScrollView *)csView atIndex:(NSInteger)index
{
    if (csView == _footerScroll) {
        self.tabBarController.selectedIndex =2;
    }
    
}



#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
//    [self.mainScroll.header endRefreshing];
    
    if (tag==HK_HK_kADBannerTag) {
        
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            self.imageArray = database[@"result"];
           
            self.headerScroll.delegate=self;
            self.headerScroll.datasource=self;
            [self.headerScroll showImageArray:self.imageArray   withAnimation:YES];
            
        }
        
    }else if (tag==HK_HK_footerADBannerTag) {
        
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            self.footerImageArray = database[@"result"];
            self.footerScroll.delegate=self;
            self.footerScroll.datasource=self;
            [self.footerScroll showImageArray:self.footerImageArray   withAnimation:YES];
        }
        
    }else if (tag == HK_HK_queryCountTwo ){
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            
        }else  {
            NSArray * array = database[@"result"];
            [_indexTwoArray removeAllObjects];
            for (NSDictionary * dic in array) {
                [_indexTwoArray addObject:dic];
                
            }
            _DetailServiceCollectionView.dataSource = self;
            _DetailServiceCollectionView.delegate = self;
            [_DetailServiceCollectionView reloadData];
        }

    } else if (tag == HK_HK_contactInformation){
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
        }else  {
            
            _phoneNum = [NSString stringWithFormat:@"%@",database[@"result"]];
        }
    }else if (tag == HK_HK_hotRecommendTag){
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
        }else  {
            _hotRecommendArray = database[@"result"];
            _tableView.dataSource = self;
            _tableView.delegate =self;
            [_tableView reloadData];
        }
    }
}
-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
//        [self.scroView.header endRefreshing];
        //
        [self dismissWaitDialog];
        
        
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
